package com.gaoda.booksystem.sysService.impl;


import com.gaoda.booksystem.entity.User;
import com.gaoda.booksystem.mapper.SysAdminMapper;
import com.gaoda.booksystem.sysService.SysAdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysAdminServiceImpl implements SysAdminService {

    @Autowired
    SysAdminMapper sysAdminMapper;

    //根据用户ID查找管理员
    @Override
    public User findAdminById(int id) {
        return sysAdminMapper.findAdminById(id);
    }

    //模糊查询 + 分页
    @Override
    public List<User> queryAdmin(String name, String userSex, String userDep, String userState, int currentPage, int pageCount) {
        return sysAdminMapper.queryAdmin(name, userSex, userDep, userState, (currentPage - 1) * pageCount, pageCount*currentPage);
    }

    //获得总页数
    @Override
    public int getTotalPage(int pageCount, String name, String userSex, String userDep, String userState) {
        Integer total = sysAdminMapper.getTotalPage(name, userSex, userDep, userState);
        return (total - 1) / pageCount + 1;

    }

    //删除管理员
    @Override
    public int deleteAdminById(int id) {
        return sysAdminMapper.deleteAdminById(id);
    }

    //启用管理员
    @Override
    public int updateAdmin(User user) {
        return sysAdminMapper.updateAdmin(user);
    }

    //禁用管理员
    @Override
    public int modifyAdmin(User user) {
        return sysAdminMapper.modifyAdmin(user);
    }

    //修改管理员信息
    @Override
    public int updateAdminById(User user) {
        return sysAdminMapper.updateAdminById(user);
    }

    //添加管理员
    @Override
    public int insertAdmin(User user) {
        return sysAdminMapper.insertAdmin(user);
    }

    //修改管理员密码
    @Override
    public int updatePwd(User user) {
        return sysAdminMapper.updatePwd(user);
    }

    //获取管理员信息
    @Override
    public List<User> adminList() {
        return sysAdminMapper.adminList();
    }


}
